/**
 * Created by 45865 on 2020/5/22.
 */
// <script type="text/javascript">
    $('input[name="user"]').on('blur',function () {
        var value = $(this).val()
        if (value){
            $('#usertip').html('')
        }else {
            $('#usertip').html('用户名不能为空')
        }
        $('input[name="pwd"]').on('blur',function () {
            var value = $('input[name="pwd"]').val()
            if (value){
                $('#pwdtip').html('')
            }else {
                $('#pwdtip').html('密码不能为空')
            }
        })
    })

$(function () {
//        $(document).on('click','.login-bin',function () {
    $('.login-btn').on('click',function () {

        var a
        if ($('#rem').is(":checked") == true){
            a = 1
        }else {
            a = 0
        }
        //获取输入的账号密码
        var loginName = $('input[name="user"]').val()
        var pwd = $('input[name="pwd"]').val()
        //判断用户名密码是否合法

        if (loginName){
            $('#usertip').html('')
        }else{
            $('#usertip').html('用户名不能为空')
            return
        }
        if (pwd){
            $('#pwdtip').html('')
        }else {
            $('#pwdtip').html('请输入密码')
            return
        }

        //验证通过

        login(loginName,pwd,a)

    })

})


function login(loginName,pwd,a) {
    var parmeter = "loginName=" + loginName + "&pwd=" + pwd + "&a=" + a

    $.ajax({
        url:"/userinfo/login",
        data:parmeter,
        type:"post",
        success:function (resultData){


            if ("success" == resultData){
                location.href = "/userinfo.html"
            }else {
//                        alert("账号或密码有误，请重新输入")
//                        location.href = "/user_login.html"
                $('#logintip').html('账号或密码有错')
            }


        },

    })
}
// </script>

// <script type="text/javascript">
$(function () {

        $('input[name="user1"]').on('blur',function () {
            var userName = $('input[name="user1"]').val()
            console.log(userName)
            $.post({
                url:"/userinfo/double?userName="+userName,
                //data:userName,
                //type:"post",
                success:function (data) {
                    console.log(data)
                    if (data == "fail"){
                        $('#usernametip').html("用户名已存在")
                        return false;
                    }else {
                        $('#usernametip').html("用户名可用")
                    }
                }
            })
        })



        $('.logon-btn').on('click',function () {

            var userName = $('input[name="user1"]').val()
            var pwd = $('input[name="pwd1"]').val()
            var phone = $('input[name="phone"]').val()
            if (phone) {
                if (!(/^1[3456789]\d{9}$/.test(phone))) {
                    $('#phonetip').html("手机号码有误，请重填")
                    return false
                } else {
                    $('#phonetip').html("")
                }
            }else {
                $('#phonetip').html("请填写手机号")
                return false
            }
            var params = "userName=" + userName + "&pwd=" + pwd + "&phone=" + phone

//            alert(params)
            $.ajax({
                url:"/userinfo/logon",
                data:params,
                type:"post",
//                dataType:"json",
                success:function (data) {

                    if (data == 1){
                        alert("注册成功")
                    }else {
                        alert("请重新输入")
                    }


                },



            })
        })
    })

    // </script>
    //
    //
    //
    // <script>

// </script>